﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DeepTalkDBSerice
{
    partial class Conference
    {
        /// <summary>
        /// The various states the conference rendering can be in
        /// </summary>
        public enum ConferenceState
        {
            Unrendered = 0,
            Rendering,
            Rendered
        }

        /// <summary>
        /// Current state of the conference (rendered, unrendered, etc.).
        /// </summary>
        public ConferenceState CurrentState
        {
            get
            {
                return (ConferenceState)InternalConferenceRenderState;
            }
            set
            {
                InternalConferenceRenderState = (byte)value;
            }
        }

        /// <summary>
        /// This will return a talk for use - but it is read only! No updating can be done!
        /// </summary>
        /// <param name="id"></param>
        internal static Conference FindTalkRO(int id)
        {
            using (ConferenceModelContainer cont = DBUtilities.GetConferenceContainer())
            {
                var theMeeting = from m in cont.ConferenceSet
                                 where m.Id == id
                                 select m;
                Conference c = theMeeting.FirstOrDefault();
                if (c == null)
                {
                    throw new ArgumentException("Unable to find talk with ID " + id.ToString());
                }
                return c;
            }
        }

        /// <summary>
        /// Returns the first unrenered talk, sorted in order of submission time.
        /// </summary>
        /// <returns></returns>
        internal static Conference GetFirstUnRenderedTalkRO()
        {
            using (ConferenceModelContainer cont = DBUtilities.GetConferenceContainer())
            {
                var allc = from c in cont.ConferenceSet
                           where c.InternalConferenceRenderState == (byte)Conference.ConferenceState.Unrendered
                           orderby c.Id ascending
                           select c;

                return allc.FirstOrDefault();
            }
        }
    }
}
